package org.algorithm.biubiu.wheel_1.链表;

import org.algorithm.biubiu.wheel_1.common.ListNode;
import org.junit.Test;

/**
 * @author jiazhaoxin
 * @Date 2022/2/16
 * @Desc {https://leetcode-cn.com/problems/odd-even-linked-list/submissions/}
 */
public class 奇偶链表 {


    @Test
    public  void test(){
        oddEvenList(ListNode.build(1,2,3,4,5));
    }

    public ListNode oddEvenList(ListNode head) {
        if(head==null){
            return  null;
        }
        ListNode evenHead = head.next;
        ListNode odd = head, even = head.next;
        while(even!=null&&even.next!=null){
            odd.next = even.next;
            odd = odd.next;
            even.next = odd.next;
            even = even.next;
        }
        odd.next = evenHead;
        return head;
    }
}
